package com.sl.ms.sms.controller;

import com.sl.ms.sms.dto.SendResultDTO;
import com.sl.ms.sms.dto.SmsInfoDTO;
import com.sl.ms.sms.service.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@Slf4j
@RestController
@RequestMapping("sms")
@Api(tags = "短信发送相关接口")
public class SmsController {

    @Resource
    private SmsService smsService;

    @PostMapping("send")
    @ApiOperation("发送短信")
    public List<SendResultDTO> send(@RequestBody SmsInfoDTO smsInfoDTO) {
        return this.smsService.sendSms(smsInfoDTO);
    }
}

//自己写的
/*@Slf4j
@Validated
@RestController
@Api(tags = "短信管理")
@RequestMapping("/sms")
public class SmsController {
    @Resource
    private SmsService smsService;

    @PostMapping("send/new/{phoneNum}")
    @ApiOperation(value = "发送通知类短信-注册新用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phoneNum", value = "手机号", required = true, dataTypeClass = String.class)})
    public String sendPhone(@PathVariable(value = "phoneNum") String phoneNum) {
        String message = this.smsService.sendPhone(phoneNum);
        return message;
    }

    @PostMapping("send/update/{phoneNum}")
    @ApiOperation(value = "发送通知类短信-更换手机号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phoneNum", value = "手机号", required = true, dataTypeClass = String.class)})
    public String sendUpdatePhone(@PathVariable(value = "phoneNum") String phoneNum) {
        String message = this.smsService.sendUpdatePhone(phoneNum);
        return message;
    }

    @PostMapping("send/code/{phoneNum}")
    @ApiOperation(value = "发送验证码短信")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phoneNum", value = "手机号", required = true, dataTypeClass = String.class)})
    public String sendCode(@PathVariable(value = "phoneNum") String phoneNum){
        int randomNumber = ThreadLocalRandom.current().nextInt(100000, 1000000);
        String code = String.valueOf(randomNumber);
        String message = this.smsService.sendCode(phoneNum, code);
        return message;
    }
}*/
